package com.ls.blog.controller;

/**
 * @program: myblog
 * @author: lishun
 * @create: 2021-07-11 09:43
 **/

import com.ls.blog.annotation.LogAnnotation;
import com.ls.blog.api.ArticleService;
import com.ls.blog.api.CategoryService;
import com.ls.blog.result.JsonResult;
import com.ls.blog.result.ResultCode;
import com.ls.blog.utils.ResultTool;
import com.ls.blog.vo.CategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 文章分类
 */
@Api(tags = {"文章分类模块"})
@RestController
public class CategoryController {

    @Autowired
    CategoryService categoryService;
    @Autowired
    ArticleService articleService;
    @ApiOperation("获得所有分类")
    @LogAnnotation(module = "分类",operation = "获得所有分类")
    @GetMapping("/categorys")
    public JsonResult category(){
        CategoryVo categories= categoryService.findCategoryList();
        return ResultTool.success(categories);
    }

    @ApiOperation("获得分类下的文章列表")
    @LogAnnotation(module = "分类",operation = "获得所有分类")
    @GetMapping("/categories/{id}")
    public JsonResult<Map<String,Object>> categoryArticleList(@PathVariable("id") Long id, Long current){
        Map<String, Object> map = articleService.categoryArticles(id, current);
        return ResultTool.success(ResultCode.LOGIN_SUCCESS,map);
    }


    @ApiOperation("所有分类细节")
    @GetMapping("/detail")
    public JsonResult<List<CategoryVo>> categoryDetail(){
        return ResultTool.success(categoryService.categoryDetail());
    }

    @ApiOperation("指定分类细节")
    @GetMapping("/detail/{id}")
    public JsonResult<CategoryVo> categoryDetailById(@PathVariable("id") Long id){
        return ResultTool.success(categoryService.categoryDetailById(id));
    }




}
